/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Entity mapped to table "Mail".
 */
import { Id } from "@ohos/dataorm"
import { NotNull } from "@ohos/dataorm"
import { Columns } from "@ohos/dataorm"
import { Entity } from "@ohos/dataorm"
import { Unique } from "@ohos/dataorm"
import { Index } from "@ohos/dataorm"
import { ToMany } from "@ohos/dataorm"
import { ColumnType } from "@ohos/dataorm"
import { ToOne } from "@ohos/dataorm"
import { FolderType } from 'coremail/Index'

export enum FolderId {
  ROOT,
  INBOX,
  IMPORTANT,
  DRAFT,
  SENT,
  DELETED,
  VIRUS,
  SPAM
}

/**
 * 每个账号自动生成
 * 收件箱 - 0
 * 已发送 - 1
 * 已删除 - 2
 * 垃圾邮件 - 3
 * [{ value: "id",  unique: true }]
 * 需要一个方法,将文件夹顺序排序. 一个tree的结构.
 */
//表名
@Entity("folder")
export class FolderEntity {
  static tableName = "folder";

  //自增id sqlite不支持创建自增非主键列.
  @Id({ isPrimaryKey: true, autoincrement: true })
  @Columns({ columnName: "id", types: ColumnType.num })
  id: number = 0;

  @Columns({ columnName: "name", types: ColumnType.str })
  name: string = ""

  /**
   * 全路径名称
   */
  // @Columns({ columnName: "full_name", types: ColumnType.str })
  // fullName: string = ""


  @Columns({ columnName: "parent_id", types: ColumnType.num })
  parentId: number|null = null;


  @Columns({ columnName: "unread_count", types: ColumnType.num })
  unReadCount: number = 0;

  @Columns({ columnName: "type", types: ColumnType.num })
  type: number = FolderType.other


  /*
  这个字段不需要存储,在解析的时候可以算出来.
  文件夹的级别,0级是root.
  但是已经存了,也没什么问题,多一个字段也能减少计算量,不需要再改了.
   */
  @Columns({ columnName: "level", types: ColumnType.num })
  level: number = 0

  /**
   * 邮件总数,服务器返回字段.
   */
  @Columns({ columnName: "mailCount", types: ColumnType.num })
  mailCount:number = 0;

  /**
   * 排序号,服务器返回字段,根据服务器返回顺序排序.
   */
  @Columns({ columnName: "order_num", types: ColumnType.num })
  orderNum:number = 0;


  //是否可以展开
  isExpandable = false;

  constructor(
    id?: number,
    name?: string,
    // fullName?:string,
    parentId?: number,
    unReadCount?: number,
    level?: number,
    type?: number,
    mailCount?:number,
    orderNum?:number
  ) {
    this.id = id
    this.name = name
    this.parentId = parentId
    // this.fullName = full_name
    this.unReadCount = unReadCount
    this.type = type == null ? FolderType.other : type
    this.level = level
    this.mailCount = mailCount
    this.orderNum = orderNum
  }

  public static FOLDER_ENTITY_ROOT = new FolderEntity(FolderId.ROOT, "", null, 0, 0, FolderType.root)
}